# 0. Compile and package project
mvn clean package

# 1. Login as admin
echo "[Test1] Login as admin, expected: login success, current user: admin"
java -jar target/cinema-management-1.0-SNAPSHOT-jar-with-dependencies.jar --login --user admin

# 2. Add manager and cashier
echo "[Test2] Add manager, expected: add user success"
java -jar target/cinema-management-1.0-SNAPSHOT-jar-with-dependencies.jar --add-user --id u2 --username manager --role MANAGER --superior admin
echo "[Test3] Add cashier, expected: add user success"
java -jar target/cinema-management-1.0-SNAPSHOT-jar-with-dependencies.jar --add-user --id u3 --username cashier --role CASHIER --superior u2

# 3. Test user management functions
echo "[Test4] Update user info, expected: update success"
java -jar target/cinema-management-1.0-SNAPSHOT-jar-with-dependencies.jar --update-user --id u2 --username newmanager --role MANAGER --superior admin

# 4. Add movie and screening room
echo "[Test5] Add movie, expected: add movie success"
java -jar target/cinema-management-1.0-SNAPSHOT-jar-with-dependencies.jar --add-movie --id m1 --name "The Wandering Earth" --duration 120
echo "[Test6] Add screening room, expected: add room success"
java -jar target/cinema-management-1.0-SNAPSHOT-jar-with-dependencies.jar --add-room --id r1 --name "IMAX Hall" --rows 10 --cols 15

# 5. Switch to manager, add schedule
echo "[Test7] Switch to manager, expected: login success, current user: u2"
java -jar target/cinema-management-1.0-SNAPSHOT-jar-with-dependencies.jar --login --user u2
echo "[Test8] Manager add schedule, expected: add schedule success"
java -jar target/cinema-management-1.0-SNAPSHOT-jar-with-dependencies.jar --add-schedule --id s1 --movie m1 --room r1 --start "2025-07-18 14:00" --end "2025-07-18 16:00"

# 6. Switch to cashier, sell ticket
echo "[Test9] Switch to cashier, expected: login success, current user: u3"
java -jar target/cinema-management-1.0-SNAPSHOT-jar-with-dependencies.jar --login --user u3
echo "[Test10] Cashier sell ticket, expected: sell ticket success"
java -jar target/cinema-management-1.0-SNAPSHOT-jar-with-dependencies.jar --sell-ticket --schedule s1 --row 3 --col 5 --phone 13800138000

# 7. Query seat status and statistics
echo "[Test11] Query seat status, expected: some seats marked as X (sold), others as O (available)"
java -jar target/cinema-management-1.0-SNAPSHOT-jar-with-dependencies.jar --seat-status --schedule s1
echo "[Test12] Query seat statistics, expected: show sold and available seat counts"
java -jar target/cinema-management-1.0-SNAPSHOT-jar-with-dependencies.jar --seat-statistics --schedule s1

# 8. Query all movies, rooms, schedules
echo "[Test13] Query all movies, expected: contains The Wandering Earth"
java -jar target/cinema-management-1.0-SNAPSHOT-jar-with-dependencies.jar --list-movies
echo "[Test14] Query all rooms, expected: contains IMAX Hall"
java -jar target/cinema-management-1.0-SNAPSHOT-jar-with-dependencies.jar --list-rooms
echo "[Test15] Query all schedules, expected: contains s1 schedule"
java -jar target/cinema-management-1.0-SNAPSHOT-jar-with-dependencies.jar --list-schedules

# 9. Test query functions
echo "[Test16] Query current movies, expected: show currently showing movies"
java -jar target/cinema-management-1.0-SNAPSHOT-jar-with-dependencies.jar --current-movies
echo "[Test17] Query schedule by movie name, expected: show schedules for The Wandering Earth"
java -jar target/cinema-management-1.0-SNAPSHOT-jar-with-dependencies.jar --query-schedule-by-movie --name "The Wandering Earth"
echo "[Test18] Query schedule by room, expected: show schedules for r1 room"
java -jar target/cinema-management-1.0-SNAPSHOT-jar-with-dependencies.jar --query-schedule-by-room --room r1
echo "[Test19] Query schedule by time range, expected: show schedules in specified time range"
java -jar target/cinema-management-1.0-SNAPSHOT-jar-with-dependencies.jar --query-schedule-by-time --start "2025-07-18 12:00" --end "2025-07-18 18:00"

# 10. Test delete functions (requires admin permission)
echo "[Test20] Switch to admin, expected: login success, current user: admin"
java -jar target/cinema-management-1.0-SNAPSHOT-jar-with-dependencies.jar --login --user admin
echo "[Test21] Delete schedule, expected: delete success"
java -jar target/cinema-management-1.0-SNAPSHOT-jar-with-dependencies.jar --delete-schedule --id s1
echo "[Test22] Delete room, expected: delete success"
java -jar target/cinema-management-1.0-SNAPSHOT-jar-with-dependencies.jar --delete-room --id r1
echo "[Test23] Delete user, expected: delete success"
java -jar target/cinema-management-1.0-SNAPSHOT-jar-with-dependencies.jar --delete-user --id u3

# 11. Verify delete results
echo "[Test24] Query all schedules, expected: schedule has been deleted"
java -jar target/cinema-management-1.0-SNAPSHOT-jar-with-dependencies.jar --list-schedules
echo "[Test25] Query all rooms, expected: room has been deleted"
java -jar target/cinema-management-1.0-SNAPSHOT-jar-with-dependencies.jar --list-rooms

# 12. Logout
echo "[Test26] Logout, expected: logged out"
java -jar target/cinema-management-1.0-SNAPSHOT-jar-with-dependencies.jar --logout

echo "=== Test Complete ==="
echo "All tests have been executed, please check the above output results to see if they meet expectations." 